package com.skydonkey.utils;

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.springframework.web.multipart.MultipartFile;

import com.drew.imaging.mp4.Mp4MetadataReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.mp4.Mp4Directory;
import org.springframework.web.multipart.MultipartFile;


import java.io.InputStream;

public class SkydonkeyUtils {

    public static String encodePassword(String password, String username){
        return MD5Utils.md5WithSalt(password, username);
    }



    public static long getVideoDuration(MultipartFile file) {
        try (InputStream inputStream = file.getInputStream()) {
            // 读取视频文件的元数据
            Metadata metadata = Mp4MetadataReader.readMetadata(inputStream);

            // 从元数据中提取视频时长信息
            Mp4Directory directory = metadata.getFirstDirectoryOfType(Mp4Directory.class);
            if (directory != null && directory.containsTag(Mp4Directory.TAG_DURATION)) {
                // 时长是以毫秒为单位, /1000得到秒
                return directory.getLong(Mp4Directory.TAG_DURATION)/1000;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }
}
